using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Zosnn.Models.Mapping
{
    public class ProductMap : EntityTypeConfiguration<Product>
    {
        public ProductMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(50);

            this.Property(t => t.SmallPic)
                .HasMaxLength(500);

            this.Property(t => t.Spec)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Product");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.TypeID).HasColumnName("TypeID");
            this.Property(t => t.Price).HasColumnName("Price");
            this.Property(t => t.SellerID).HasColumnName("SellerID");
            this.Property(t => t.SmallPic).HasColumnName("SmallPic");
            this.Property(t => t.Staus).HasColumnName("Staus");
            this.Property(t => t.Spec).HasColumnName("Spec");
            this.Property(t => t.Created).HasColumnName("Created");

            // Relationships
            this.HasOptional(t => t.ProductType)
                .WithMany(t => t.Products)
                .HasForeignKey(d => d.TypeID);

        }
    }
}
